package main

import "fmt"

func main() {
	t3()

	arr1 := []int{1, 2, 3}
	fmt.Printf("%p\n", arr1)
	//切片传递，是引用传递
	t5(arr1)
	fmt.Println(arr1)
}

// 切片传递是引用传递
func t5(arr []int) {
	fmt.Printf("t5 %p\n", arr)
	arr[0] = 3
}

func t0() {
	p1 := new(int)
	fmt.Printf("p1 --> %#v \n ", p1)           //p1 --> (*int)(0xc00001a098)
	fmt.Printf("p1 point to --> %#v \n ", *p1) //p1 point to --> 0

	var p2 *int
	i := 0
	p2 = &i
	fmt.Printf("p2 --> %#v \n ", p2)           // p2 --> (*int)(0xc00001a0a8)
	fmt.Printf("p2 point to --> %#v \n ", *p2) //p2 point to --> 0
}

func t1() {
	var m1 map[int]string
	if m1 == nil {
		fmt.Printf("m1 is nil --> %#v \n ", m1) //m1 is nil --> map[int]string(nil)
	}

	m2 := make(map[int]string)
	if m2 == nil {
		fmt.Printf("m2 is nil --> %#v \n ", m2)
	} else {
		fmt.Printf("m2 is not nil --> %#v \n ", m2) //m2 is not nil --> map[int]string{}
	}
}

func t2() {
	var c1 chan string
	if c1 == nil {
		fmt.Printf("c1 is nil --> %#v \n ", c1) //(chan string)(nil)
	}

	c2 := make(chan string)
	if c2 == nil {
		fmt.Printf("c2 is nil --> %#v \n ", c2)
	} else {
		fmt.Printf("c2 is not nill --> %#v \n ", c2) //(chan string)(0xc420016120)
	}
}

func t3() {
	var a []int
	fmt.Printf("%#v\n", a == nil)
	fmt.Printf("a = %v\n", a)

	b := []int{2}
	t4(b)
	fmt.Printf("b = %v\n", b)

	var c = make([]int, 0)

	fmt.Printf("c = %v\n", c)

	d := make([]int, 0)
	fmt.Printf("d = %v\n", d)
}

func t4(p []int) {
	p = append(p, 1)
	fmt.Println("p=", p)
}
